﻿using Microsoft.AspNetCore.Mvc;
using SimpleInOutControl.Attributes;
using SimpleInOutControl.Common;
using SimpleInOutControl.DBModels;
using SimpleInOutControl.Services;
using SimpleInOutControl.Utility;

namespace SimpleInOutControl.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class DeviceInfoController: ControllerBase
    {
        DeviceInfoService service = new DeviceInfoService();

        [HttpPost]
        public ResponseResult<bool> AddData(DeviceInfo dto)
        {
            var result = service.AddData(dto);
            return new ResponseResult<bool>()
            {
                Code = result ? 0 : 1,
                Message = result ? "成功" : "失败",
                Result = result
            };
        }

        [HttpPut]
        public ResponseResult<bool> UpdateData(DeviceInfo dto)
        {
            var result = service.UpdateData(dto);
            return new ResponseResult<bool>()
            {
                Code = result ? 0 : 1,
                Message = result ? "成功" : "失败",
                Result = result
            };
        }

        [HttpDelete]
        public ResponseResult<bool> DeleteData(int id)
        {
            var result = service.DeleteData(id);
            return new ResponseResult<bool>()
            {
                Code = result ? 0 : 1,
                Message = result ? "成功" : "失败",
                Result = result
            };
        }

        [HttpGet]
        public ResponseResult<DeviceInfo> GetData(int id)
        {
            var result = service.GetData(id);
            return new ResponseResult<DeviceInfo>()
            {
                Code = result != null ? 0 : 1,
                Message = result != null ? "成功" : "失败",
                Result = result 
            };
        }

        [HttpGet]
        public ResponseResult<List<DeviceInfo>> GetPageData(PagingRequest<UserInfo> dto)
        {
            DeviceInfoService service = new DeviceInfoService();
            var result = service.GetPageData(dto);
            return new ResponseResult<List<DeviceInfo>>()
            {
                Code = result != null ? 0 : 1,
                Message = result != null ? "成功" : "失败",
                Result = result 
            };
        }
    }
}
